package com.wuyou.controller;

import com.wuyou.domain.Result;
import com.wuyou.domain.bo.AdvTypeBO;
import com.wuyou.domain.vo.AdvTypeVO;
import com.wuyou.service.IAdvTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 刘雷雨
 * @since 2022-09-29
 */
@RestController
@RequestMapping("/advType")
@Api(value = "广告分类接口")
public class AdvTypeController {

    @Autowired
    private IAdvTypeService advTypeService;


    @ApiOperation(value = "查询广告类型")
    @GetMapping
    public Result findAdvTypeList( ) {
        try {
            List<AdvTypeBO> advTypeList = advTypeService.getAdvTypeList();
            List<AdvTypeVO> advTypeVOS = new ArrayList<>();
            for (AdvTypeBO advTypeBO : advTypeList) {
                AdvTypeVO advTypeVO = new AdvTypeVO();
                BeanUtils.copyProperties(advTypeBO,advTypeVO);
                advTypeVOS.add(advTypeVO);
            }
            return Result.OK().setData(advTypeVOS);
        } catch (BeansException e) {
            e.printStackTrace();
            return Result.ERROR();
        }
    }
}
